//
//  TogetherToolbar.m
//  Together_iOS
//
//  Created by QIU Shuang on 3/1/14.
//  Copyright (c) 2014 QIU Shuang. All rights reserved.
//

#import "TogetherToolbar.h"

@interface TogetherToolbar()

@property (nonatomic, strong) UIButton *leftButton;
@property (nonatomic, strong) UIButton *rightButton;

@end

@implementation TogetherToolbar

@synthesize delegate = _delegate;

@synthesize leftButton = _leftButton;
@synthesize rightButton = _rightButton;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        UIColor *fontColor = [[UIColor alloc] initWithRed:0.565 green:0.565 blue:0.565 alpha:1.0];
        UIButton *hotTracks = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 160, 44)];
        [hotTracks setTitle:@"热门线路" forState:UIControlStateNormal];
        [hotTracks setTitleColor:fontColor forState:UIControlStateNormal];
        [hotTracks addTarget:self.delegate action:@selector(hotTracks) forControlEvents:UIControlEventTouchUpInside];
        hotTracks.backgroundColor = [[UIColor alloc] initWithRed:0.965 green:0.957 blue:0.918 alpha:1];
        [self addSubview:hotTracks];
        self.leftButton = hotTracks;
        
        UIButton *myProfile = [[UIButton alloc] initWithFrame:CGRectMake(161, 0, 160, 44)];
        [myProfile setTitle:@"我的线路" forState:UIControlStateNormal];
        [myProfile setTitleColor:fontColor forState:UIControlStateNormal];
        [myProfile addTarget:self.delegate action:@selector(myTrack) forControlEvents:UIControlEventTouchUpInside];
        myProfile.backgroundColor = [[UIColor alloc] initWithRed:0.965 green:0.957 blue:0.918 alpha:1];
        [self addSubview:myProfile];
        self.rightButton = myProfile;
        
        // border
        UIColor *delimiterColor = [[UIColor alloc] initWithRed:0.902 green:0.886 blue:0.882 alpha:1.0];
        UIView *bhDelimiter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 2)];
        [bhDelimiter setBackgroundColor:delimiterColor];
        [self addSubview:bhDelimiter];
        
        UIView *bvDelimiter = [[UIView alloc] initWithFrame:CGRectMake(159, 0, 2, 44)];
        [bvDelimiter setBackgroundColor:delimiterColor];
        [self addSubview:bvDelimiter];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void) leftButtonClicked {
    self.leftButton.backgroundColor = [[UIColor alloc] initWithRed:255./255. green:114./255. blue:19./255. alpha:1.0];
    self.leftButton.titleLabel.textColor = [UIColor whiteColor];
}

- (void) rightButtonClicked {
    self.rightButton.backgroundColor = [[UIColor alloc] initWithRed:255./255. green:114./255. blue:19./255. alpha:1.0];
    self.rightButton.titleLabel.textColor = [UIColor whiteColor];
}

@end
